<?php !defined("IN_SYSTEM") && exit("ACCESS DENY");?>
{template header}
{template top}
<div id="uc">
{template uc/left}
	<div id="uc_main">
		<div class="uc_tab">
			<ul>
			<li><span><a{if !isset($action)} class="on"{/if} href="{url home.php?m=product}">所有菜单</a></span></li>
			<li><span><a{if $action == 'cate'} class="on"{/if} href="{url home.php?m=product&f=cate}">菜单类别</a></span></li>
			<li><span><a{if $action == 'add'} class="on"{/if} href="{url home.php?m=product&f=add}">添加菜单</a></span></li>
			</ul>
		</div>
		<div id="uc_contain">
		{if getGP('f') == 'list' || getGP('f') == 'special' || !getGP('f')}
			<form action="{url home.php?m=product&f=$action}" method="POST" class="uc_search">
		搜索菜单: <input type="text" name="search_field" class="txt" size="32" onclick="if(this.value=='输入菜名'){ this.value='';}" onblur="if(this.value==''){ this.value='输入菜名';}" id="search_field" value="{if $field}{$field}{else}输入菜名{/if}"/>
			<input type="submit" value="{$lang['search']}"/>
			</form>
			<table class="uc_table" >
				<tr>
				<th>菜名</th><th>菜价</th><th>所属类别</th><th>月供应</th><th>月售出</th><th>评论</th><th>人气</th><th>状态</th><th>{$lang['operation']}</th>
				</tr>
		{loop $datas $data}
			<tr id="tr{$data['pid']}">
			<td>{$data['title']}</td>
			<td>{$data['price']}</td>
			<td>{$categorys[$data['cid']]['catename']}</td>
			<td>{$data['stock']}</td>
			<td>{$data['orders']}</td>
			<td>{$data['comments']}</td>
			<td>{$data['views']}</td>
			<td>{if $data['status']<1}已售完{else}出售中{/if}</td>
			<td><a href="{url home.php?m=product&f=edit&id=$data[pid]}" target="_blank" >[{$lang['change']}]</a> <a href="{url home.php?m=product&f=del&id=$data[pid]}" onclick="return confirm_delete();" target="_blank">[{$lang['delete']}]</a> <a href="{url home.php?f=good&a=detail&id=$data[pid]}" target="_blank">[{$lang['detail']}]</a></td>
			</tr>
		{/loop}
			</table>
			{$pager}
		{/if}
		{if getGP('f') == 'add' || getGP('f') == 'edit'}
			<form name="friend_add" method="post" action="{url('home.php?m=product&f=save')}" enctype="multipart/form-data">
			<input type="hidden" name="pid" value="{$data['pid']}" />
			<table cellspacing="0" class="uc_fa_table">
		<tr>
			<td class="td1">菜名：</td>
			<td colspan="3"><input type="text" name="title" class="input" size="52" value="{$data['title']}" /></td>
		</tr>
		<tr>
				<td>所属类别：</td>
				<td colspan="3">
				<select name="cid" id="cid">
					<option value="0">请选择类别</option>
					{loop $categorys $cate}
					<option value="{$cate['cid']}" {if $cate['cid'] == $data['cid']}selected="selected"{/if}>{$cate['catename']}</option>
					{/loop}
				</select>
					<span><a href="javascript:;" onclick="$('#createcadiv').toggle();">添加类别</a></span>
					<div id="createcadiv">
					<h3><a href="javascript:;" onclick="$('#createcadiv').toggle();" title="{$lang['close']}" style="float:right;">×</a>添加类别</h3>
						<p>类别名称：<input type="text" name="ucatename" id="ucatename" class="input"/></p>
						<p><input type="button" class="button" onclick="useraddcates();" value="保存类别"/></p>
					</div>
				状态：
				<select name="status">
					<option value="1" {if $data['status'] == 1}selected="selected"{/if}>出售中</option>
					<option value="0" {if $data['status'] == 0}selected="selected"{/if}>已售完</option>
				</select>
				
				&nbsp;&nbsp;<input type="checkbox" name="special" {if $data['recommend']} checked="checked"{/if} id="special" title="勾选上表示此道菜是特色菜">&nbsp;特色菜</input>
				
				</td>
			</tr>
		<tr>
			<td class="td1">菜价：</td>
			<td colspan="3"><input type="text" name="price" class="input" size="52"  onblur="this.value=money(this.value);" value="{$data['price']}" /></td>
		</tr>
		<tr>
			<td class="td1">每月供应：</td>
			<td colspan="3"><input type="text" name="stock" class="input" size="52" value="{$data['stock']}" /></td>
		</tr>
		<tr>
			<td class="td1" valign="top">配料详情：</td>
			<td colspan="3"><textarea  name="detail" cols="51" >{$data['content']}</textarea></td>
		</tr>
		<tr>
			<td class="td1">菜单图片：</td>
			<td colspan="4"><img src="{if $data['image']}{DATA_DIR}files/{$data['image']}{/if}" style="width:60px;height:70px;float:left;margin-right:5px;"></img>
			<a href="javascript:;">上传图片:</a><br/>
			<input type="file" name="image" id="image" size="17"/><br/>
			<span class="uc_tips">请上传180x135像素的图片</span>
			</td>
		</tr>
		<tr class="bg2"><td></td><td colspan="3"><input type="submit" class="button" value="{$lang['submit']}" /> </td></tr>
	</table>
	</form>
		<script type="text/javascript">
	function useraddcates(){
		var name=$('#ucatename').val();
		var cstatus= $("input[name='cstatus']:checked").val();
		if(name.length<2){alert('分类名称不能少于两个字符');return false;}
		$.getJSON("home.php?m=product&f=savecate"+"&name="+encodeURIComponent(name)+"&cstatus="+cstatus+'&tm='+Math.random(),'',function(data){
			if(data.mstatus==true){
				var obj = document.getElementById("cid");
					obj.options.add(new Option(data.catename, data.cid));
					obj.options[obj.options.length-1].selected=true;
				$('#createcadiv').hide();
			}else{
				alert(data.msg);
				$('#ucatename').focus();
			}
			});

	}
				</script>
				
				
		{/if}
		{if getGP('f') == 'del'}
		{/if}
		{if getGP('f')=='cate'}
		<table class="uc_table" >
				<tr>
				<th>类别名</th><th>菜单数量</th><th>{$lang['operation']}</th>
				</tr>
		{loop $datas $data}
			<tr id="tr{$data['cid']}">
			<td>{$data['catename']}</td>
			<td>{$data['total']}</td>
			<td><a href="#" target="_blank" onclick="editcate('{$data[catename]}','{$data[total]}',{$data[cid]});return false;">[{$lang['change']}]</a> <a href="{url home.php?m=product&f=del&id=$data[pid]}" onclick="return confirm_delete();" target="_blank">[{$lang['delete']}]</a></td>
			</tr>
		{/loop}
			</table>
		{/if}
	<script type="text/javascript">
	function userupdatecates(id){
		var name=$('#ucatename').val();
		var total= $("#total").val();
		if(name.length<2){alert('分类名称不能少于两个字符');return false;}
		$.getJSON("home.php?m=product&f=savecate&id="+id+"&name="+encodeURIComponent(name)+"&total="+total+'&tm='+Math.random(),'',function(data){
			if(data.mstatus==true){
				window.parent.location.reload();
			}else{
				alert(data.msg);
			}
			});

	}
	function editcate(u,n,id){
		var edit = art.dialog({
		    title: '编辑类别',
		    lock: true,
		    fixed: true, //C=G.DW
		    width:350,
		    height:250,
		    padding:'10px 0 0 15px',
		    cssname:'uc_editfrind',
		    content: '<p>类别名称：<input type="text" size="30" name="ucatename" id="ucatename" value="'+u+'" class="input"/></p>'+
					 '<p>类单数量：<input type="text" size="30" name="total" id="total" value="'+n+'" class="input"/></p>'+
					 '<br/><p><input type="button" class="button" onclick="userupdatecates('+id+');" value="保存类别"/></p>'
			});
		
		return false;
	}
	</script>	
		</div>
	</div>

	<div id="uc_right"></div>
</div>
<script type="text/javascript">
function chanfefriend(u){
	var edit = art.dialog({
	    title: '{$lang['change_friend']}',
	    lock: true,
	    fixed: true, //C=G.DW
	    width:560,
	    height:400,
	    padding:'0 0 0 15px',
	    cssname:'uc_editfrind',
	    content: '<iframe src="'+u+'" frameborder="0" style="width:560px;height:400px;" />'
		});
	
	return false;
}
function deletefrind(u,id){
	if(confirm('{$lang["confirm_delete"]}')){
		$.getJSON(u+'&tm='+Math.random(),'',function(data){
			if(data.status==true){
				$('#'+id).hide();
			}else{
				art.dialog({fixed: true,time: 2,content: data.msg});
			}
			});
	}
	return false;
	
}
</script>

{template footer}